package com.le.tester.javaThink.fifth.chapter12_Collections;

import com.le.tester.javaThink.fourth.typeinfo.pets.Hamster;
import com.le.tester.javaThink.fourth.typeinfo.pets.Pet;
import com.le.tester.javaThink.fourth.typeinfo.pets.Pets;
import com.le.tester.javaThink.fourth.typeinfo.pets.Rat;

import java.util.LinkedList;

/**
 * createTime：2021/8/27 15:51
 * description：LinkedListFeatures
 */
public class LinkedListFeatures {
    public static void main(String[] args) {
        LinkedList<Pet> pets = new LinkedList<>(Pets.arrayList(5));
        System.out.println(pets);

        //只有获取，没有移除，抛异常 start
        System.out.println("pets.getFirst" + pets.getFirst());
        System.out.println("pets.element()" + pets.element());
        //只有获取，没有移除，抛异常 end

        //取出为null start
        System.out.println("pets.peek" + pets.peek());
        //取出为null end

        //移除后返回头部元素 抛异常 start
        System.out.println("pets.remove" + pets.remove());
        System.out.println("pets.removeFirst" + pets.removeFirst());
        //移除后返回头部元素 抛异常 end

        System.out.println("pets.poll()" + pets.poll());
        System.out.println(pets);

        pets.addFirst(new Rat());
        System.out.println("after addFirst()" + pets);
        pets.offer(new Hamster());
        System.out.println("after offer():" + pets);

        pets.add(new Hamster());
        System.out.println("after add()" + pets);

        pets.addLast(new Hamster());
        System.out.println("after addLast()" + pets);

        System.out.println("pets.removeLast()" + pets.removeLast());


    }
}
